﻿Japan Pro Golf Tour 64 Results Password Decoder v1.0

Introduction:
  At the end of a network tournament in "Japan Pro Golf Tour 64" you'll be asked to save your game.  Opening that save file will display a page of stats as well as a password.  Originally, you would have entered this password into a webpage dedicated to the game on Randnet to share your results, and in the case of multi-day tournaments, qualifying players would receive new Network Tournament passwords for the next day of competition.
  That not being an option in this day and age, this program decrypts and decodes those passwords, displaying the data they contain.  Simply provide the original Network Tournament password used to start the game and the Results password.

  Results passwords vary in length from 5 to 40 characters.  In their simplest form only the current day, tournament ID, and a checksum is encoded.  More complicated passwords include the player name, play statistics, individual hole scores, etc.  A flag field in the net tournament password dictates the data encoded in the results.
  The packed binary data is LCG encrypted, then split into 5-bit indicies and encoded as the string displayed.  The LCG seed is derived from your unique player ID assigned by Randnet, the current day, and tournament number.  Decryption requires knowing these values to regenerate the lookup table, as well as what output fields to expect.


Requirements:
  Something that runs 64bit Windows executables; tested on Vista, Win7, & Win10.
  Some degree of Japanese font support.


Usage:
  In the unfortunately obvious event this readme is not circulated with the executable, hovering over pretty much any element of the program will provide a bit of information about what that field is.

  Usage is fairly simple.  Type the original Net Tournament password into the upper box.  If it can't be decoded or a checksum error occurs, a message will be displayed.  Otherwise, a subset of the data encoded in the password will appear.
  * Data from this password is required to read the results password.  Only enter the password used to start the game.  Others will not decode the results.

  After inputting the Net Tournament password, type the Results password into the appropriate field.  Tabs and newlines will be ignored, but spaces have value in the passwords and still count.
  If the Results password is valid, the correct Net Tournament password was provided, and checksum is correct, the results will be decoded and displayed in a box below the password.  In the event of an error, a message will appear instead.
  Note only the data encoded in the password will be displayed.  If no data was recorded then the password is only confirmation of completion, and a message will appear to that effect.


  Although not a console program, through some trickery you can also use this from the command line.  Either redirect output to a file (" -> example.txt") or end the line with " | more".  Please note malformed data isn't filtered terribly well.

  Decode [results] password using [net] password:
pswddec decode [-h] net results

  Instead of using a net password, you can also provide the information sourced from it and manually decode the [results].  You need to provide [flags] for which fields were encoded, as well as [playerID], [tournament], and [today] to generate the decryption seed.  Note that [today] should range 0-3, not 1-4.
pswddec manual [-h] playerID tournament today flags results

  If you would like to cheat, it's also possible to encode new results passwords ;*)
pswddec encode [-h] playerID tournament today [...]

  As an example, try plugging this into the command line:
pswddec decode ウトミホレヒスロイキフイウヒカオレカウイ ニイケキカホタテエロヘホフノトレルハムネサラレノサキタハミサコテヒホネルチケム | more


Notes:
*) Total and hole scores have already applied the player's handicap.
*) Not all encoded player names will decode to their original strings.  When they are encoded as 7-bit values, errors in the table cause some characters to overlap, some (like vowel replacements, but not all vowel replacements) are ignored, and others are encoded incorectly (long vowel becomes dash).  They are obviously errors, as the values they should be are skipped and nothing takes their place.  The original table is used here, as patching it would lead to incompatible passwords.
*) Hole scores are capped, ranging -4 to 3, to fit within three bits.  Anything worse than a triple bogey won't be obvious here, but the total score reflects actual strokes.
*) In the event that you are playing in a hurricane, drive distances are capped at 510 yards.  511 is a special value to indicate none was recorded.
*) Likewise, near pin distances cap at 254, with 255 indicating none recorded.

-Zoinkity
